local xiaoren = fk.CreateSkill{
  name = "hanqing__xiaoren",
}

Fk:loadTranslationTable{
  ["hanqing__xiaoren"] = "啸刃",
  [":hanqing__xiaoren"] = "你可以将任意张♠牌当作需额外弃置等量张牌响应的刺【杀】使用；你可以失去所有体力，令此【杀】增加等量的伤害基数值。",

  ["#hanqing__xiaoren"] = "啸刃：你可以将任意张♠牌当一张刺【杀】使用，目标响应时需额外弃置等量的牌！",
  ["#hanqing__xiaoren-invoke"] = "啸刃：你可以失去所有体力，令此刺【杀】增加等量伤害！",
  ["#hanqing__xiaoren-discard"] = "请弃置%arg2张手牌，否则%arg依然对你生效",
}

xiaoren:addEffect("viewas", {
  anim_type = "offensive",
  mute_card = false,
  pattern = "stab__slash",
  prompt = "#hanqing__xiaoren",
  handly_pile = true,
  card_filter = function (self, player, to_select, selected)
    return Fk:getCardById(to_select).suit == Card.Spade
  end,
  view_as = function(self, player, cards)
    if #cards == 0 then return end
    local card = Fk:cloneCard("stab__slash")
    card.skillName = xiaoren.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local n = player.hp
    if n > 0 and
      room:askToSkillInvoke(player, {
        skill_name = xiaoren.name,
        prompt = "#hanqing__xiaoren-invoke",
      }) then
      use.additionalDamage = n
      room:loseHp(player, n, xiaoren.name)
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
})

xiaoren:addEffect(fk.BeforeRequestAsk, {
  can_refresh = function (self, event, target, player, data)
    if player.seat == 1 then
      local card_effect = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect, true)
      if card_effect then
        local use = card_effect.data
        if table.contains(use.card.skillNames, xiaoren.name) and data and data.focus_text == "stab__slash_skill" then
          event:setCostData(self, {extra_data = use})
          return true
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    data = data or {}
    local use = event:getCostData(self).extra_data
    local n = 1 + #Card:getIdList(use.card)
    for _, v in pairs(data.data) do
      v[2] = "#hanqing__xiaoren-discard:::"..use.card:toLogString()..":"..n
      v[4].num = n
      v[4].min_num = n
    end
  end,
})

xiaoren:addAI(nil, "vs_skill")

return xiaoren
